﻿using hlib.IO;
using QntPlatform.Strategy;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace QntPlatform
{

    public interface IStrategy
    {
          ISysFun SysFun { get; }
          ISysApi SysApi { get; }
          ITAFun TA { get; }
         IExchange Exchange { get; }
       virtual  void OnExit(Exception ex=null){
             Console.WriteLine(ex);
         }
         void MainFun();
        virtual void Init(){
             Console.WriteLine("Init:"+GetType().Name+GetHashCode());
         }
    }
    public abstract class StrategyBase:IStrategy
    {
        public ISysFun SysFun { get; }
        public ISysApi SysApi { get; }
        public ITAFun TA { get; }
        public IExchange Exchange { get; }

        public StrategyBase(IExchange exchange, ISysFun sysFun, ISysApi sysApi, ITAFun ta)
        {
            Exchange = exchange;
            SysFun = sysFun;
            SysApi = sysApi;
            TA = ta;
        }
        public virtual void Init() { }
        public virtual void MainFun(IDictionary<string,object> context)
        {
            MainFun();
        }
         public virtual void MainFun(){}
        public virtual void OnExit(Exception ex=null) { }
    }

    public abstract class StrategyPart : StrategyBase
    {

        public StrategyPart(IStrategy parent) : base(parent.Exchange, parent.SysFun, parent.SysApi, parent.TA)
        {
            Parent = parent;
        }

        public IStrategy Parent { get; }
        public override void MainFun()
        {
        }
        ILog log = LogManager.GetLogger();
        internal IConvertible execTrade(SideDirection direction, decimal amount,object info=null)
        {
            IConvertible id = null;
          
           id= Exchange.CreateOrder(amount, direction, -1).Result;
            log.Debug("交易完成：", new { direction, amount, id,info });
            return id;
        }
    }
    
}
